package pers.course.week9;

import java.util.*;

public class Thimbles {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cases = in.nextInt();
        for (int i = 0; i < cases; i++) {
            int num = in.nextInt();
            Map<Character, Boolean> map = new TreeMap<>();
            map.put('1', true);
            map.put('2', false);
            map.put('3', false);
            for (int j = 0; j < num; j++) {
                String str = in.next().replace("-", "");
                char[] ch = str.toCharArray();
                boolean temp = map.get(ch[0]);
                map.put(ch[0], map.get(ch[1]));
                map.put(ch[1], temp);
            }
            Set<Character> keys = map.keySet();
            for (Character key : keys) {
                if (map.get(key)) {
                    System.out.println(key);
                }
            }
        }
    }
}
